/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.xtd.model.employment;

import com.xtd.model.admin.Xtduser;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.hibernate.annotations.IndexColumn;

/**
 *
 * @author Lu Yuanbin
 */
@Entity
@Table(name = "employee")
@NamedQueries({
    @NamedQuery(name = "Employee.findAll", query = "SELECT e FROM Employee e")})
public class Employee implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id")
    private Integer id;
    @Column(name = "name")
    private String name;
    @Column(name = "gender")
    private String gender;
    @Column(name = "birthday")
    @Temporal(TemporalType.DATE)
    private Date birthday;
    @Column(name = "idCardNum")
    private String idCardNum;
    @Column(name = "phone")
    private String phone;
    @Column(name = "address")
    private String address;
    @Column(name = "email")
    private String email;
    @Lob
    @Column(name = "pic")
    private byte[] pic;
    @Column(name = "remarks")
    private String remarks;
    @Column(name = "baseSalary")
    private BigDecimal baseSalary;
    @Column(name = "active")
    private boolean active;
    @JoinColumn(name = "department_post_id", referencedColumnName = "id")
    @ManyToOne(optional = false)
    private DepartmentPost departmentPost;
    @JoinColumn(name = "xtduser_username", referencedColumnName = "username")
    @ManyToOne(cascade = CascadeType.ALL)
    private Xtduser xtduser;
    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
    @JoinColumn(name = "employee_id")
    @IndexColumn(name = "payroll_position", base = 0)
    private List<Payroll> payrollRecordCollection;
    @JoinColumn(name = "last_payroll", referencedColumnName = "id")
    @ManyToOne
    private Payroll lastPayroll;

    public Employee() {
    }

    public boolean isNew() {
        if (id == null) {
            return true;

        } else {
            return false;
        }
    }

    public Employee(Integer id) {
        this.id = id;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }

    public String getIdCardNum() {
        return idCardNum;
    }

    public void setIdCardNum(String idCardNum) {
        this.idCardNum = idCardNum;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public byte[] getPic() {
        return pic;
    }

    public void setPic(byte[] pic) {
        this.pic = pic;
    }

    public String getRemarks() {
        return remarks;
    }

    public void setRemarks(String remarks) {
        this.remarks = remarks;
    }

    public BigDecimal getBaseSalary() {
        return baseSalary;
    }

    public void setBaseSalary(BigDecimal baseSalary) {
        this.baseSalary = baseSalary;
    }

    public DepartmentPost getDepartmentPost() {
        return departmentPost;
    }

    public void setDepartmentPost(DepartmentPost departmentPost) {
        this.departmentPost = departmentPost;
    }

    public Xtduser getXtduser() {
        return xtduser;
    }

    public void setXtduser(Xtduser xtduser) {
        this.xtduser = xtduser;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Employee)) {
            return false;
        }
        Employee other = (Employee) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return name + " " + gender ;
    }

    /**
     * @return the payrollRecordCollection
     */
    public List<Payroll> getPayrollRecordCollection() {
        return payrollRecordCollection;
    }

    /**
     * @param payrollRecordCollection the payrollRecordCollection to set
     */
    public void setPayrollRecordCollection(List<Payroll> payrollRecordCollection) {
        this.payrollRecordCollection = payrollRecordCollection;
    }

    /**
     * @return the gender
     */
    public String getGender() {
        return gender;
    }

    /**
     * @param gender the gender to set
     */
    public void setGender(String gender) {
        this.gender = gender;
    }

    /**
     * @return the active
     */
    public boolean isActive() {
        return active;
    }

    /**
     * @param active the active to set
     */
    public void setActive(boolean active) {
        this.active = active;
    }

    /**
     * @return the lastPayroll
     */
    public Payroll getLastPayroll() {
        return lastPayroll;
    }

    /**
     * @param lastPayroll the lastPayroll to set
     */
    public void setLastPayroll(Payroll lastPayroll) {
        this.lastPayroll = lastPayroll;
    }
}
